package org.jackysoft.aop;

import java.text.DecimalFormat;

import org.jackysoft.entity.AbstractEntity;
import org.jackysoft.util.StringUtils;

public aspect FieldFormater {
	pointcut formatDouble():execution(public Double org.jackysoft.entity..*.get*());
	
	pointcut getStringTrim():execution(public String org.jackysoft.entity..*.get*());
	
	pointcut setStringTrim(String val):execution(void org.jackysoft.entity..*.set*(String))
	   && this(AbstractEntity)  
	   && args(val);
	
	
    private static final String dpattern ="######0.0000";
	
    
    Double around():formatDouble(){
		Double dbl = proceed();	
		return formatDoubleValue(dbl,dpattern);
	}
		
	Double formatDoubleValue(Double dbl,String pattern){
	
		DecimalFormat df = new DecimalFormat(pattern);
		String sdbl = "0";
		if (dbl != null)
			sdbl = df.format(dbl);
		return Double.valueOf(sdbl);
	}
	
	void around(String value):setStringTrim(value){
		 
		 proceed(StringUtils.trim(value));
	}
	
	String around():getStringTrim(){
		return StringUtils.trim(proceed());
	}
	
	
}